package github.kawaiior.yuanchuxiuzhen.common.entity.addon.model;

import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import github.kawaiior.yuanchuxiuzhen.common.entity.addon.KirinEntity;
import github.kawaiior.yuanchuxiuzhen.util.RenderUtil;
import net.minecraft.client.renderer.entity.model.EntityModel;
import net.minecraft.client.renderer.model.ModelRenderer;
import net.minecraft.util.math.MathHelper;

public class KirinEntityModel extends EntityModel<KirinEntity> {
    private final ModelRenderer head;
    
    private final ModelRenderer body;
    
    private final ModelRenderer rightarm;
    
    private final ModelRenderer leftarm;
    
    private final ModelRenderer leftleg;
    
    private final ModelRenderer rightleg;

    public KirinEntityModel(){
        this.textureWidth=126;
        this.textureHeight=122;
        this.head=new ModelRenderer(this);
        this.head.setRotationPoint(0.0F,-20.0F,-18.0F);
        addBox(this.head, 44, 0, -5.0F, -22.0F, -7.0F, 10, 27, 7, 0.0F, false);
        addBox(this.head, 78, 0, 0.0F, -32.0F, 0.0F, 0, 27, 12, 0.0F, false);
        addBox(this.head, 0, 33, -4.0F, -44.0F, 0.0F, 0, 14, 14, 0.0F, false);
        addBox(this.head, 0, 33, 4.0F, -44.0F, 0.0F, 0, 14, 14, 0.0F, false);
        addBox(this.head, 0, 19, 6.0F, -35.0F, -5.0F, 0, 14, 14, 0.0F, false);
        addBox(this.head, 0, 19, -6.0F, -35.0F, -5.0F, 0, 14, 14, 0.0F, false);
        addBox(this.head, 28, 34, -4.0F, -22.0F, -9.0F, 8, 17, 2, 0.0F, false);
        addBox(this.head, 48, 34, -5.0F, 5.0F, -5.0F, 10, 4, 5, 0.0F, false);
        addBox(this.head, 0, 0, -5.0F, -32.0F, -12.0F, 10, 10, 12, 0.0F, false);
        addBox(this.head, 0, 22, -4.0F, -27.0F, -18.0F, 8, 5, 6, 0.0F, false);
        this.body=new ModelRenderer(this);
        this.body.setRotationPoint(0.0F,-24.0F,4.0F);
        addBox(this.body, 0, 66, -8.0F, -1.0F, -22.0F, 16, 16, 16, 0.0F, false);
        addBox(this.body, 0, 98, -6.0F, 2.0F, -6.0F, 12, 14, 10, 0.0F, false);
        addBox(this.body, 50, 92, -7.0F, 0.0F, 4.0F, 14, 16, 14, 0.0F, false);
        addBox(this.body, 106, 96, 0.0F, 0.0F, 18.0F, 0, 16, 10, 0.0F, false);
        this.rightarm=new ModelRenderer(this);
        this.rightarm.setRotationPoint(-8.0F,-14.0F,-11.0F);
        addBox(this.rightarm, 92, 77, -6.0F, -6.0F, -5.0F, 6, 19, 10, 0.0F, false);
        addBox(this.rightarm, 110, 52, -4.0F, 13.0F, -3.0F, 4, 21, 4, 0.0F, false);
        addBox(this.rightarm, 64, 83, -4.5F, 34.0F, -5.0F, 5, 4, 5, 0.0F, false);
        addBox(this.rightarm, 0, 19, -7.0F, -10.0F, -5.0F, 0, 14, 14, 0.0F, false);
        this.leftarm=new ModelRenderer(this);
        this.leftarm.setRotationPoint(8.0F,-14.0F,-11.0F);
        addBox(this.leftarm, 92, 77, 0.0F, -6.0F, -5.0F, 6, 19, 10, 0.0F, false);
        addBox(this.leftarm, 110, 52, 0.0F, 13.0F, -3.0F, 4, 21, 4, 0.0F, false);
        addBox(this.leftarm, 64, 83, -0.5F, 34.0F, -5.0F, 5, 4, 5, 0.0F, false);
        addBox(this.leftarm, 0, 19, 7.0F, -10.0F, -5.0F, 0, 14, 14, 0.0F, false);
        this.leftleg=new ModelRenderer(this);
        this.leftleg.setRotationPoint(7.0F,-14.0F,16.0F);
        addBox(this.leftleg, 92, 77, 0.0F, -6.0F, -5.0F, 6, 19, 10, 0.0F, false);
        addBox(this.leftleg, 110, 52, 0.0F, 13.0F, 0.0F, 4, 21, 4, 0.0F, false);
        addBox(this.leftleg, 64, 83, -0.5F, 34.0F, -2.0F, 5, 4, 5, 0.0F, false);
        addBox(this.leftleg, 0, 19, 7.0F, -10.0F, -5.0F, 0, 14, 14, 0.0F, false);
        this.rightleg=new ModelRenderer(this);
        this.rightleg.setRotationPoint(-7.0F,-14.0F,16.0F);
        addBox(this.rightleg, 92, 77, -6.0F, -6.0F, -5.0F, 6, 19, 10, 0.0F, false);
        addBox(this.rightleg, 110, 52, -4.0F, 13.0F, 0.0F, 4, 21, 4, 0.0F, false);
        addBox(this.rightleg, 64, 83, -4.5F, 34.0F, -2.0F, 5, 4, 5, 0.0F, false);
        addBox(this.rightleg, 0, 19, -7.0F, -10.0F, -5.0F, 0, 14, 14, 0.0F, false);
        
        
    }

    private void addBox(ModelRenderer mb, int tx, int ty, float x, float y, float z, float width, float height, float depth, float delta, boolean mirrorIn){
        ModelRenderer mr = new ModelRenderer(this);
        mb.addChild(mr);
        mr.setTextureOffset(tx, ty).addBox(x,y,z,width,height,depth,delta,mirrorIn);
    }

    @Override
    public void setRotationAngles(KirinEntity entityIn, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) {
        this.head.rotateAngleY = netHeadYaw / 57.295776F;
        this.head.rotateAngleX = headPitch / 57.295776F;
        this.rightleg.rotateAngleX = MathHelper.cos(limbSwing * 1.0F) * 1.0F * limbSwingAmount;
        this.rightarm.rotateAngleX = MathHelper.cos(limbSwing * 0.6662F + 3.1415927F) * limbSwingAmount;
        this.leftleg.rotateAngleX = MathHelper.cos(limbSwing * 1.0F) * -1.0F * limbSwingAmount;
        this.leftarm.rotateAngleX = MathHelper.cos(limbSwing * 0.6662F) * limbSwingAmount;
    }

    @Override
    public void render(MatrixStack matrixStackIn, IVertexBuilder bufferIn, int packedLightIn, int packedOverlayIn, float red, float green, float blue, float alpha) {
        this.head.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn);
        this.body.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn);
        this.rightarm.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn);
        this.leftarm.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn);
        this.leftleg.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn);
        this.rightleg.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn);
    }
}